package com.vision.core.cm.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Mark
 *
 */
public class TaskNode implements Serializable {
	
	private static final long serialVersionUID = 730017300617045554L;
	
	public enum NodeType {
		BUTTON,
		MENU,
		BUTTON_MENU
	}
	
	private String id;
	private String text;
	private String tooltip;
	private NodeType type;
	
	private List<TaskNode> children;
	
	public TaskNode() {
		// No-args constructor for serialization to work
	}
	
	public TaskNode(TaskNode node) {
		this(node.getId(), node.getText(), node.getTooltip(), NodeType.MENU);
	}
	
	public TaskNode(TaskNode node, NodeType type) {
		this(node.getId(), node.getText(), node.getTooltip(), type);
	}
	
	public TaskNode(String id, String text, String tooltip) {
		this(id, text, tooltip, NodeType.MENU);
	}
	
	public TaskNode(String id, String text, String tooltip, NodeType type) {
		this.id = id;
		this.text = text;
		this.tooltip = tooltip;
		this.type = type;
	}

	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getText() {
		return text;
	}
	
	public void setText(String text) {
		this.text = text;
	}
	
	public String getTooltip() {
		return tooltip;
	}
	
	public void setTooltip(String tooltip) {
		this.tooltip = tooltip;
	}
	
	public NodeType getType() {
		return type;
	}

	public void setType(NodeType type) {
		this.type = type;
	}

	public boolean hasChildren() {
		return children != null && !children.isEmpty();
	}
	
	public List<TaskNode> getChildren() {
		return children;
	}
	
	public void setChildren(List<TaskNode> children) {
		this.children = children;
	}
	
	public void addChildren(TaskNode ... children) {
		if (this.children == null)
			this.children = new ArrayList<TaskNode>();
		
		for (TaskNode child : children)
			this.children.add(child);
	}
	
	// Object Methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	@Override
	public int hashCode() {
		return id == null ? 0 : id.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (id == null || !(obj instanceof TaskNode))
			return false;
		
		TaskNode t = (TaskNode) obj;
		return id.equals(t.id);
	}

}
